﻿#region License
// <copyright file="PrimaryKeyAttribute.cs" company="Kopigi - Marc Plessis">
// Copyright © Kopigi 2011
// </copyright>
// ****************************************************************************
// <author>Marc Plessis</author>
// <email>marc.plessis@kopigi.fr</email>
// <date>03/04/2011</date>
// <project>Biwo</project>
// <web>http://www.kopigi.fr/biwo</web>
// <license>
// See license.txt in this solution or http://www.microsoft.com/opensource/licenses.mspx
// </license>
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace SQLServer.Repository.POCO.Generated
{
    [AttributeUsage(AttributeTargets.Property)]
    public class PrimaryKeyAttribute : Attribute
    {
        /// <summary>
        /// Retrieve informations on PrimariesKey in Entity
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<PropertyInfo> GetPrimariesKeyInfo<T>()
        {
            PropertyInfo[] entityProperties = typeof(T).GetProperties();
            return from prop in entityProperties
                   let attrs = prop.GetCustomAttributes(false)
                   where attrs.Any(obj => obj.GetType() == typeof(PrimaryKeyAttribute))
                   select prop;
        }
    }
}
